package com.nuanshui.heatedloan.userinfo.service.thirdLogin;

import com.nuanshui.framework.consts.TransactionManagerType;
import com.nuanshui.heatedloan.userinfo.constant.LoginAccountType;
import com.nuanshui.heatedloan.userinfo.dal.mapper.WeiboUserMapper;
import com.nuanshui.heatedloan.userinfo.facade.thirdlogin.ThirdUserServiceConstant;
import com.nuanshui.heatedloan.userinfo.form.BoundUserForm;
import com.nuanshui.heatedloan.userinfo.model.ThirdUser;
import com.nuanshui.heatedloan.userinfo.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

/**
 * Created by zxh on 2017/2/10.
 */
@Service(ThirdUserServiceConstant.WeiboUserService)
@Transactional(readOnly=true,value= TransactionManagerType.USER_INFO_TRANSACTION_MANAGER)
public class WeiboUserServiceImpl extends BaseThirdUserServiceImpl implements Serializable{

    @Autowired
    private WeiboUserMapper weiboUserMapper;
    
    public User loadUser( String openId) {
        return weiboUserMapper.loadUserByWeibo(openId);
    }


    public ThirdUser loadThirdUser(String userId) {
        return weiboUserMapper.loadUserWeibo(userId);
    }

   @Transactional(value=TransactionManagerType.USER_INFO_TRANSACTION_MANAGER)
    public void insertThirdUser(BoundUserForm boundUserForm) {
    	weiboUserMapper.insertUserWeibo(boundUserForm);
    }

    @Transactional(value=TransactionManagerType.USER_INFO_TRANSACTION_MANAGER)
    public void updateOpenId(String userId) {
        ThirdUser thirdUser = loadThirdUser(userId);
        weiboUserMapper.updateUserWeiboUserId(userId,thirdUser.getOpenid());
    }

    @Override
    @Transactional(value=TransactionManagerType.USER_INFO_TRANSACTION_MANAGER)
    public void deleteUser(String userId)
    {
    	weiboUserMapper.deleteUserWeibo(userId);
    }

    public int[] getMutexAccountTypes()
    {
        int accountTypes[]={LoginAccountType.QQ,LoginAccountType.WEI_XIN};
        return accountTypes;
    }

    protected String getExistUserError()
    {
        return "该微博账号已绑定其他用户";
    }

    protected String getExistThirdUserError()
    {
        return "账号已经被其他微博账号绑定";
    }



}
